<!DOCTYPE html>
<?php
require_once ('conn.php');

if($_POST['outlogin']==1){
    unset($_SESSION['userid']);
    unset($_SESSION['name']);
    unset($_SESSION['role']);
    echo "y";die;
}

if($_POST['login']==1){
   $pass =md5($_POST['pass']);
   $user = mysql_fetch_row(mysql_query("select id,name,role from ci_staff where number='".$_POST['name']."' and pass='".$pass."'"));//验证用户
   if($user[0]>1){
       $_SESSION['userid']=$user[0];
       $_SESSION['name']=$user[1];
       $_SESSION['role']=$user[2];
       $_POST=array();
       if($user[2]==2){
           Header("Location:supply_index.php"); 
       }elseif($user[2]==3){
           Header("Location:dotlistMaster.php"); 
       }
       else{
           Header("Location:index.php"); 
       }
       
       die;
   }else{
       echo "<script>alert('用户名或密码有误');</script>";
   }
   
}

?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优易购 - 登陆</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/login.css">
    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>
    <div class="top">
       
        <span>登陆</span>
        
    </div>
    <form action="login.php" onsubmit="return form(this)"   method="post">
        <div class="login">
            <div class="lg">
                <img src="img/logo2.png" alt="">
            </div>

            <div class="input">
                <p>用户名</p>
                <img src="img/user.png" alt="">
                <input type="text" name="name" id="name" placeholder="请输入您的用户名">
            </div>

            <div class="input">
                <p>密码</p>
                <img src="img/pass.png" alt="">
                <input type="password" name="pass" id="pass" placeholder="请输入您的密码">
            </div>
            <input type="hidden" name="login" value="1">
            <input type="submit" class="sub" value="登陆">
        </div>
    </form>
</body>    
<script>
    function form(f){
        
        if(f.name.value==""){
            alert('用户名不能为空');
            f.name.focus();
            return false;
        }
        if(f.pass.value==""){
            alert('密码不能为空');
            f.pass.focus();
            return false;
        }

    }
</script>
</html>